package jp.eisbahn.mgapi.api.photo;

import jp.eisbahn.mgapi.api.Response;
import jp.eisbahn.mgapi.http.HttpResponse;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

/**
 * This class parses the response which has ID only.
 * @author Yoichiro Tanaka
 */
public class PhotoIdResponse extends Response {

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Response#parseResponse(
     * jp.eisbahn.mgapi.http.HttpResponse)
     */
    @Override
    public final void parseResponse(final HttpResponse httpResponse) {
        String responseBody = httpResponse.getResponseBody();
        Object parsed = JSONValue.parse(responseBody);
        if (parsed instanceof JSONObject) {
            JSONObject entry = (JSONObject) parsed;
            addEntry(new ID(entry));
        } else {
            throw new IllegalStateException(
                    "Response is not JSON object. " + responseBody);
        }
    }

}
